#include "queue.h"

int enQueue(queue_t * pQueue,int net_fd){

    node_t*pNew = (node_t*)calloc(1,sizeof(node_t));
    pNew->net_fd = net_fd;

    if (pQueue->size == 0)
    {
        pQueue->head = pNew;
        pQueue->end = pNew;
    }else{
        pQueue->end->pNext = pNew;
        pQueue->end = pNew;
    }
    pQueue->size++;
    
    return 0;

}
int deQueue(queue_t * pQueue, int *pValue){//出队，删除头节点

    if (pQueue->size == 0)
    {
        return -1;
    }
    
    node_t* temp = pQueue->head;
    *pValue = temp->net_fd;

    if (pQueue->size == 1)
    {
        pQueue->end = NULL;
        pQueue->head = NULL;
    }else 
    {
        pQueue->head = pQueue->head->pNext;
    }
    
    free(temp);
    pQueue->size--;
    return 0;
}